package com.mhy.crash;

import android.os.Build;
import android.util.Log;

/**
 * @author mahongyin 2020-04-16 13:25 @CopyRight mhy.work@qq.com
 *
 * @description: ExceptionAppliction e=(new ExceptionAppliction()).getExceptionAppliction();
 */
public class ExceptionAppliction implements Thread.UncaughtExceptionHandler {
    private static final String TAG = "ExceptionAppliction"; //单例
    private static ExceptionAppliction exceptionAppliction;

    private ExceptionAppliction() {
    }

    public static ExceptionAppliction getExceptionAppliction() {
        if (exceptionAppliction == null) {
            exceptionAppliction = new ExceptionAppliction();
        }
        Thread.setDefaultUncaughtExceptionHandler(exceptionAppliction);
        return exceptionAppliction;
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        String model = Build.MODEL; //模型
        String brand = Build.BRAND;
//     手机品牌
        int sdkInt = Build.VERSION.SDK_INT;
//     版本
        Log.i(TAG, "uncaughtException: " + model);
        Log.i(TAG, "uncaughtException: " + brand);
        Log.i(TAG, "uncaughtException: " + sdkInt);
//     退出app
       System.exit(1);
    }
}

